import os

import numpy as np
import imageio.v2 as imageio
from main.config import path


def concatenate(images):
    images = [imageio.imread(img) for img in images]
    img = np.vstack(images)  # 等价于 np.concatenate(images, axis=0)
    return img


def save(name, img):
    save_path = os.path.join(path, name)
    imageio.imwrite(save_path, img)


def concatenate_and_save(name, images):
    img = concatenate(images)

    if name[-4:] not in ['.jpg', '.png']:
        name = name + '.png'
    save(name, img)


